﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLL.Business;
using System.Data.SqlClient;
using System.Data;
using DAL;


namespace BLL.Controler
{
    public class KQHKTongHopCtrl
    {

        public static IList<KQDiemTongHopTheoKyInfo> LayDsKQHocKyTongHop(String maLop, String maHocKy)
        {

            //BangDiemBUO bd = new BangDiemBUO();

            //KQHocKyTongHopData m_KQHKTHData = new KQHocKyTongHopData();
            //DataTable m_DT = m_KQHKTHData.LayDsKQHocKyTongHopForReport(maLop, maHocKy, maNamHoc);

            IList<KQDiemTongHopTheoKyInfo> dS = new List<KQDiemTongHopTheoKyInfo>();
            BangDiemBUO bdBUO = new BangDiemBUO();
            String idLop = maLop;
            String idHocSinh;
            double diem = 0;
            int dem = 0;
            foreach (String item in bdBUO.getAllIdHocSinhByIdLop(idLop))
            {
                //InsertBangDiem(item);
                idHocSinh = item;
                //foreach (DataRow Row in bdBUO.KetQuaHKTheoLop(maHocKy, maLop).Rows)
                ////{
                //    diem += Convert.ToDouble(Row["DiemTongKet"]);
                //}
                try
                {
                    foreach (String item1 in bdBUO.showBangDiemTheoHocSinhCuaTatCaMon(maHocKy, idHocSinh))
                    {
                        diem += double.Parse(item1);
                        dem++;
                        diem = (double)(diem*1.0 / dem);
                    }
                }
                catch (Exception)
                {
                    
                    
                }
                
                KQDiemTongHopTheoKyInfo ketqua = new KQDiemTongHopTheoKyInfo();
                ketqua.DiemTongKet = diem;
                ketqua.id_HocSinh = bdBUO.getHS(idHocSinh).id_HocSinh.ToString();
                ketqua.HoTenHS = bdBUO.getHS(idHocSinh).HoTenHS.ToString();
                ketqua.NgaySinh = bdBUO.getHS(idHocSinh).NgaySinh.ToString();
                
                dS.Add(ketqua);
                diem = 0;dem=0;

            }

            
            //foreach (DataRow Row in m_DT.Rows)
            //{
            //    KQHocKyTongHopInfo ketqua = new KQHocKyTongHopInfo();

            //    HocSinhInfo hs = new HocSinhInfo();
            //    hs.MaHocSinh = Convert.ToString(Row["MaHocSinh"]);
            //    hs.HoTen = Convert.ToString(Row["HoTen"]);

            //    LopInfo l = new LopInfo();
            //    l.MaLop = Convert.ToString(Row["MaLop"]);
            //    l.TenLop = Convert.ToString(Row["TenLop"]);

            //    HocKyInfo hk = new HocKyInfo();
            //    hk.MaHocKy = Convert.ToString(Row["MaHocKy"]);
            //    hk.TenHocKy = Convert.ToString(Row["TenHocKy"]);

            //    NamHocInfo nh = new NamHocInfo();
            //    nh.MaNamHoc = Convert.ToString(Row["MaNamHoc"]);
            //    nh.TenNamHoc = Convert.ToString(Row["TenNamHoc"]);

            //    HocLucInfo hl = new HocLucInfo();
            //    hl.MaHocLuc = Convert.ToString(Row["MaHocLuc"]);
            //    hl.TenHocLuc = Convert.ToString(Row["TenHocLuc"]);

            //    HanhKiemInfo hkiem = new HanhKiemInfo();
            //    hkiem.MaHanhKiem = Convert.ToString(Row["MaHanhKiem"]);
            //    hkiem.TenHanhKiem = Convert.ToString(Row["TenHanhKiem"]);

            //    ketqua.HocSinh = hs;
            //    ketqua.Lop = l;
            //    ketqua.HocKy = hk;
            //    ketqua.NamHoc = nh;
            //    ketqua.HocLuc = hl;
            //    ketqua.HanhKiem = hkiem;
            //    ketqua.DTBMonHocKy = Convert.ToSingle(Row["DTBMonHocKy"]);

            //    dS.Add(ketqua);
            //}
            return dS;

        }

    }
}
